
	*------------------------------------------------------------------------------------------------------------%	
	* Figure D5: Effects on hiring from large retailers by large retailer employment share decile
	*------------------------------------------------------------------------------------------------------------%	

	* Load event info
	use "$data/cb/events.dta", clear
	rename eventid trt_exp
	rename mdate mwdate
	tempfile events
	save `events'
	
	* Load CZ-level data
	use "$data/cb/stacked_poaching.dta", clear
	
	* Merge event info
	merge m:1 trt_exp using `events', keepusing(mwdate mw share_affected months*) keep(3) nogen
	
	replace etime=mdate-(mwdate+1) if missing(etime)

	gen am_empshare=(employment_share_q_all_decile>5)

	* Keep in time frame
	keep if inrange(etime, -12, 11)
	
	* Indicator for post policy
	gen postperiod = etime>=0

	* Large retailers' own gap
	preserve                                                                                                                               
		 
	* All
	* Generate treatment variable
	keep if balanced_long==1
	egen T_std=std(T)
	gen D = T_std*postperiod
	
	foreach outcome of varlist ln_new_hires_other ln_new_hires ln_new_hires_policy {
		reghdfe `outcome' c.D##i.employment_share_q_all_decile if balanced_long==1, absorb(i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		parmest, saving("$figures_tables/reg_output/spillover_`outcome'_all" ,replace)
	}
	restore
	
	preserve
	* Major
	* Generate treatment variable
	keep if balanced_long==1 & share_affected>.3
	egen T_std=std(T)
	gen D = T_std*postperiod
	foreach outcome of varlist ln_new_hires_other ln_new_hires ln_new_hires_policy {
		reghdfe `outcome' c.D##i.employment_share_q_all_decile if balanced_long==1 & share_affected>.3, absorb(i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		parmest, saving("$figures_tables/reg_output/spillover_`outcome'_major" ,replace)
	}
	restore
	
	preserve
	* $15 VMW
	* Generate treatment variable
	keep if balanced_long==1 & mw==15.   
	egen T_std=std(T)
	gen D = T_std*postperiod
	foreach outcome of varlist ln_new_hires_other ln_new_hires ln_new_hires_policy {
		reghdfe `outcome' c.D##i.employment_share_q_all_decile if balanced_long==1 & mw==15, absorb(i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		parmest, saving("$figures_tables/reg_output/spillover_`outcome'_15" ,replace)
	}
	
	restore
			
	use "$figures_tables/reg_output/spillover_ln_new_hires_policy_all.dta", clear	
	keep if regexm(parm,"employment_share_q_all_decile#")
	drop if regexm(parm,"#co")
	gen decile_str=substr(parm,1,1)
	destring decile_str, gen(decile)
	replace decile=10 if decile==1
	graph tw (bar estimate decile, color("${dnwcrimson}")) (rcap min95 max95 decile, color("$dnwcrimson")),  yline(0, lpattern(solid)) legend(off) xtitle("Decile of large retailer employment share") ytitle("Effect on non-policy log new hires from large retailer") 
	graph export "$figures_tables/figd5a_hiring_spillover_effects_by_decile_all.pdf", replace
				
	use "$figures_tables/reg_output/spillover_ln_new_hires_policy_major.dta", clear	
	keep if regexm(parm,"employment_share_q_all_decile#")
	drop if regexm(parm,"#co")
	gen decile_str=substr(parm,1,1)
	destring decile_str, gen(decile)
	replace decile=10 if decile==1
	graph tw (bar estimate decile, color("${dnwcrimson}")) (rcap min95 max95 decile, color("$dnwcrimson")),  yline(0, lpattern(solid)) legend(off) xtitle("Decile of large retailer employment share") ytitle("Effect on non-policy log new hires from large retailer") 
	graph export "$figures_tables/figd5b_hiring_spillover_effects_by_decile_major.pdf", replace

	use "$figures_tables/reg_output/spillover_ln_new_hires_policy_15.dta", clear	
	keep if regexm(parm,"employment_share_q_all_decile#")
	drop if regexm(parm,"#co")
	gen decile_str=substr(parm,1,1)
	destring decile_str, gen(decile)
	replace decile=10 if decile==1
	graph tw (bar estimate decile, color("${dnwcrimson}")) (rcap min95 max95 decile, color("$dnwcrimson")),  yline(0, lpattern(solid)) legend(off) xtitle("Decile of large retailer employment share") ytitle("Effect on non-policy log new hires from large retailer")
	graph export "$figures_tables/figd5c_hiring_spillover_effects_by_decile_15.pdf", replace
	
	* Load event info
	use "$data/cb/events.dta", clear
	rename eventid trt_exp
	rename mdate mwdate
	tempfile events
	save `events'
	
	* Load CZ-level data
	use using "$data/cb/stacked_poaching.dta" if balanced_long==1, clear
	
	* Merge event info
	merge m:1 trt_exp using `events', keepusing(mwdate mw share_affected months*) keep(3) nogen
	
	replace etime=mdate-(mwdate+1) if missing(etime)

	gen am_empshare=(employment_share_q_all_decile>5)
	
	* Keep in time frame
	keep if inrange(etime, -12, 11)
	
	* Indicator for post policy
	gen postperiod = etime>=0


	* Regress ------------------------------------------------------------------
	
		eststo clear

		foreach outcome of varlist ln_new_hires_other ln_new_hires ln_new_hires_policy {

			* All
			preserve
			qui sum T,d
			local std_T=round(r(sd),.001)
			
			egen T_std=std(T)
			replace T=T_std				
			
			* Generate treatment variable
			gen D = T*postperiod
			
			eststo `outcome'a1: reghdfe `outcome' D , absorb(i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
				estadd local Tstd `std_T'
				distinct cz if e(sample) == 1
				estadd local Ncz `r(ndistinct)'
				estadd local CZFE "Y" 
				estadd local etimeFE "Y"
				sum `outcome' if e(sample) == 1 & postperiod == 0
				estadd local preMean = round(`r(mean)', 0.01) 
			restore
		
		}
	
		* Build table
		
		#d ;
		esttab ln_new_hiresa1 ln_new_hires_policya1 ln_new_hires_othera1
				using "$figures_tables/table4_market_poach_did_all.tex",  
				replace label fragment
				nolines  
				prehead("\begin{threeparttable} \begin{tabular}{lccc} \toprule \toprule & \multicolumn{3}{c}{Dep. Var.: Log new hires} \\ Independent variable") 
				posthead(\cmidrule(lr){2-4}) 
				booktabs								
				nonumbers 
				mtitles("Overall" "From Large Retailer" "From Other")
				collabels(none)  
				cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)) ) 
				starlevels(* 0.1 ** 0.05 *** 0.01) 						
				keep(D)   
				coeflabel(D "Large retailer gap X 1(Post)") 
				stats(
					N Ncz Tstd preMean CZFE etimeFE, 
					fmt(%12.0gc) 
					label("Obs" "CZs" "St. dev. large retailer gap" "Dep var pre-treat mean" "CZ FEs" "Month from event FEs")
				)
				prefoot(\midrule) 
				postfoot(\bottomrule \bottomrule \end{tabular} \end{threeparttable} )
				substitute("Log new hires - all" "\midrule \textit{Pre-treatment mean} \\ Log new hires" "CZ FEs" "\midrule CZ FEs")
		;
		#d cr
	
*------------------------------------------------------------------------------------------------------------%	
* Table 5: Market level poaching effects, heterogeneity by employment share
*------------------------------------------------------------------------------------------------------------%	
	* Load event info
	use "$data/cb/events.dta", clear
	rename eventid trt_exp
	rename mdate mwdate
	tempfile events
	save `events'
	
	* Load CZ-level data
	use using "$data/cb/stacked_poaching.dta" if balanced_long==1, clear
	
	* Merge event info
	merge m:1 trt_exp using `events', keepusing(mwdate mw share_affected months*) keep(3) nogen
	
	replace etime=mdate-(mwdate+1) if missing(etime)
	
	*keep if employment_share_decile>5
	*replace T = T*(employment_share_decile>5)
	gen am_empshare=(employment_share_q_all_decile>=7)
	
	*drop if months_since_last_policy <= 12 | months_until_next_policy <= 12


	* Keep in time frame
	keep if inrange(etime, -12, 11)
	
	* Indicator for post policy
	gen postperiod = etime>=0


	* Regress ------------------------------------------------------------------
	
		eststo clear

		foreach outcome of varlist ln_new_hires_other ln_new_hires ln_new_hires_policy {

			* All
			preserve
			keep if am_empshare==0
			qui sum T,d
			local std_T=round(r(sd),.001)
			
			egen T_std=std(T)
			replace T=T_std				
			
			* Generate treatment variable
			gen D = T*postperiod

			eststo `outcome'a1: reghdfe `outcome' D if am_empshare == 0, absorb(i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
				estadd local Tstd `std_T'
				distinct cz if e(sample) == 1
				estadd local Ncz `r(ndistinct)'
				estadd local CZFE "Y" 
				estadd local etimeFE "Y"
				sum `outcome' if e(sample) == 1 & postperiod == 0
				estadd local preMean_`outcome' = round(`r(mean)', 0.01) : ln_new_hires_othera1
				sum employment_share if e(sample) == 1
				local temp: di %4.3f `r(mean)'
				estadd local MeanEmpShare `temp'
			restore
			
			preserve
			keep if am_empshare==1
			qui sum T,d
			local std_T=round(r(sd),.001)
			
			egen T_std=std(T)
			replace T=T_std				
			
			* Generate treatment variable
			gen D = T*postperiod
			
			eststo `outcome'b1: reghdfe `outcome' D if am_empshare == 1, absorb(i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
				estadd local Tstd `std_T'
				distinct cz if e(sample) == 1
				estadd local Ncz `r(ndistinct)'
				estadd local CZFE "Y" 
				estadd local etimeFE "Y"
				sum `outcome' if e(sample) == 1 & postperiod == 0
				estadd local preMean_`outcome' = round(`r(mean)', 0.01) : ln_new_hires_otherb1
				sum employment_share if e(sample) == 1
				local temp: di %4.3f `r(mean)'
				estadd local MeanEmpShare `temp'
			restore	

			* Major
			preserve
			keep if share_affected > .3 & am_empshare==0 
			qui sum T,d
			local std_T=round(r(sd),.001)
			
			egen T_std=std(T)
			replace T=T_std				
			
			* Generate treatment variable
			gen D = T*postperiod
			
			eststo `outcome'a2: reghdfe `outcome' D if share_affected > .3 & am_empshare == 0, absorb(i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
				estadd local Tstd `std_T'
				distinct cz if e(sample) == 1
				estadd local Ncz `r(ndistinct)'
				estadd local preMean = round(`r(mean)', 0.01)
				estadd local CZFE "Y"
				estadd local etimeFE "Y"
				sum `outcome' if e(sample) == 1 & postperiod == 0
				estadd local preMean_`outcome' = round(`r(mean)', 0.01) : ln_new_hires_othera2
				sum employment_share if e(sample) == 1
				local temp: di %4.3f `r(mean)'
				estadd local MeanEmpShare `temp'
			restore
			
			preserve
			keep if share_affected > .3 & am_empshare==1
			qui sum T,d
			local std_T=round(r(sd),.001)
			
			egen T_std=std(T)
			replace T=T_std				
			
			* Generate treatment variable
			gen D = T*postperiod
			
			eststo `outcome'b2: reghdfe `outcome' D if share_affected > .3 & am_empshare == 1, absorb(i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
				estadd local Tstd `std_T'
				distinct cz if e(sample) == 1
				estadd local Ncz `r(ndistinct)'
				estadd local preMean = round(`r(mean)', 0.01)
				estadd local CZFE "Y"
				estadd local etimeFE "Y"
				sum `outcome' if e(sample) == 1 & postperiod == 0
				estadd local preMean_`outcome' = round(`r(mean)', 0.01) : ln_new_hires_otherb2
				sum employment_share if e(sample) == 1
				local temp: di %4.3f `r(mean)'
				estadd local MeanEmpShare `temp'
			restore
			
			
			* $15
			preserve
			keep if mw==15 & am_empshare==0
			qui sum T,d
			local std_T=round(r(sd),.001)
			
			egen T_std=std(T)
			replace T=T_std				
			
			* Generate treatment variable
			gen D = T*postperiod
			
			eststo `outcome'a3: reghdfe `outcome' D if mw == 15 & am_empshare == 0, absorb(i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
				estadd local Tstd `std_T'
				distinct cz if e(sample) == 1
				estadd local Ncz `r(ndistinct)'
				estadd local preMean = round(`r(mean)', 0.01)
				estadd local CZFE "Y"
				estadd local etimeFE "Y"
				sum `outcome' if e(sample) == 1 & postperiod == 0
				estadd local preMean_`outcome' = round(`r(mean)', 0.01) : ln_new_hires_othera3
				sum employment_share if e(sample) == 1
				local temp: di %4.3f `r(mean)'
				estadd local MeanEmpShare `temp'
			restore
			
			preserve
			keep if mw==15 & am_empshare==1
			qui sum T,d
			local std_T=round(r(sd),.001)
			
			egen T_std=std(T)
			replace T=T_std				
			
			* Generate treatment variable
			gen D = T*postperiod
			
			
			eststo `outcome'b3: reghdfe `outcome' D if mw == 15 & am_empshare == 1, absorb(i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
				estadd local Tstd `std_T'
				distinct cz if e(sample) == 1
				estadd local Ncz `r(ndistinct)'
				estadd local preMean = round(`r(mean)', 0.01)
				estadd local CZFE "Y"
				estadd local etimeFE "Y"
				sum `outcome' if e(sample) == 1 & postperiod == 0
				estadd local preMean_`outcome' = round(`r(mean)', 0.01) : ln_new_hires_otherb3
				sum employment_share if e(sample) == 1
				local temp: di %4.3f `r(mean)'
				estadd local MeanEmpShare `temp'
			restore
		
		}
	
		* Build table
		
		#d ;
		esttab ln_new_hiresa* ln_new_hiresb*
				using "$figures_tables/table5_market_poach_by_emp_share.tex",  
				replace label fragment
				nolines  
				prehead("\begin{threeparttable} \begin{tabular}{lcccccc} \toprule \toprule  & \multicolumn{3}{c}{Low Emp. Share} & \multicolumn{3}{c}{High Emp. Share} \\ Indep. Var.: Large Retailer Gap X 1(Post)") 
				posthead("\cmidrule(lr){2-4} \cmidrule(lr){5-7}" "Dep. Var.:  & \multicolumn{6}{c}{} \\") 
				booktabs								
				nonumbers 
				mtitles("All events" "Major events" "\\$15 events" "All events" "Major events" "\\$15 events" ) 
				collabels(none)  
				cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)) ) 
				starlevels(* 0.1 ** 0.05 *** 0.01) 						
				keep(D)   
				coeflabel(D "Log new hires") 
				noobs
		;
		esttab ln_new_hires_policya* ln_new_hires_policyb*
				using "$figures_tables/table5_market_poach_by_emp_share.tex",  
				append fragment
				nolines  
				booktabs								
				nonumbers 
				nomtitles
				collabels(none)  
				cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)) ) 
				starlevels(* 0.1 ** 0.05 *** 0.01) 						
				keep(D)   
				coeflabel(D "Log large retailer new hires") 
				noobs
		;
		esttab ln_new_hires_othera* ln_new_hires_otherb*
				using "$figures_tables/table5_market_poach_by_emp_share.tex",  
				append fragment
				nolines  
				booktabs								
				nonumbers 
				nomtitles
				collabels(none)  
				cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)) ) 
				starlevels(* 0.1 ** 0.05 *** 0.01) 						
				keep(D)   
				coeflabel(D "Log other new hires") 
				stats(
					N Ncz Tstd MeanEmpShare preMean_ln_new_hires preMean_ln_new_hires_policy preMean_ln_new_hires_other CZFE etimeFE, 
					fmt(%12.0gc) 
					label("Obs" "CZs"  "St. dev. large retailer gap" "Mean policy emp. share" "Log new hires - all" "Log large retailer new hires" "Log other new hires" "CZ FEs" "Month from event FEs")
				)
				prefoot(\midrule) 
				postfoot(\bottomrule \bottomrule \end{tabular} \end{threeparttable} )
				substitute("Log new hires - all" "\midrule \textit{Pre-treatment mean} \\ Log new hires" "CZ FEs" "\midrule CZ FEs")
		;
		#d cr

*------------------------------------------------------------------------------------------------------------%	
* Table 5:  Market level poaching effects, market gap
*------------------------------------------------------------------------------------------------------------%	
	* Load event info
	use "$data/cb/events.dta", clear
	rename eventid trt_exp
	rename mdate mwdate
	tempfile events
	save `events'
	
	* Load CZ-level data
	use using "$data/cb/stacked_poaching.dta" if balanced_long==1, clear
	
	* Merge event info
	merge m:1 trt_exp using `events', keepusing(mwdate mw share_affected months*) keep(3) nogen
	
	replace etime=mdate-(mwdate+1) if missing(etime)
	
	gen am_empshare=(employment_share_decile>5)

	* Keep in time frame
	keep if inrange(etime, -12, 11)
	
	* Indicator for post policy
	gen postperiod = etime>=0


	* Regress ------------------------------------------------------------------
	
		eststo clear

		foreach outcome of varlist ln_new_hires_other ln_new_hires ln_new_hires_policy {

			* All
			preserve
			qui sum super_gap,d
			local std_T=round(r(sd),.001)
			
			egen sg_std=std(super_gap)
			replace T=sg_std				
			
			* Generate treatment variable
			gen D = T*postperiod
			
			eststo `outcome'a1: reghdfe `outcome' D , absorb(i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
				estadd local Tstd `std_T'
				distinct cz if e(sample) == 1
				estadd local Ncz `r(ndistinct)'
				estadd local CZFE "Y" 
				estadd local etimeFE "Y"
				sum `outcome' if e(sample) == 1 & postperiod == 0
				estadd local preMean_`outcome' = round(`r(mean)', 0.01) : ln_new_hires_othera1
			restore

			* Major
			preserve
			keep if share_affected > .3
			qui sum super_gap,d
			local std_T=round(r(sd),.001)
			
			egen sg_std=std(super_gap)
			replace T=sg_std				
			
			* Generate treatment variable
			gen D = T*postperiod
			
			eststo `outcome'a2: reghdfe `outcome' D if share_affected > .3, absorb(i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
				estadd local Tstd `std_T'
				distinct cz if e(sample) == 1
				estadd local Ncz `r(ndistinct)'
				estadd local preMean = round(`r(mean)', 0.01)
				estadd local CZFE "Y"
				estadd local etimeFE "Y"
				sum `outcome' if e(sample) == 1 & postperiod == 0
				estadd local preMean_`outcome' = round(`r(mean)', 0.01) : ln_new_hires_othera2
			restore	
				
			* $15
			preserve 
			keep if mw == 15
			qui sum super_gap,d
			local std_T=round(r(sd),.001)
			
			egen sg_std=std(super_gap)
			replace T=sg_std				
			
			* Generate treatment variable
			gen D = T*postperiod
			
			eststo `outcome'a3: reghdfe `outcome' D if mw == 15, absorb(i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
				estadd local Tstd `std_T'
				distinct cz if e(sample) == 1
				estadd local Ncz `r(ndistinct)'
				estadd local preMean = round(`r(mean)', 0.01)
				estadd local CZFE "Y"
				estadd local etimeFE "Y"
				sum `outcome' if e(sample) == 1 & postperiod == 0
				estadd local preMean_`outcome' = round(`r(mean)', 0.01) : ln_new_hires_othera3
			restore
		
		}
	
		* Build table
		
		#d ;
		esttab ln_new_hiresa*
				using "$figures_tables/table5_sg_market_poach_did.tex",  
				replace label fragment
				nolines  
				prehead("\begin{threeparttable} \begin{tabular}{lcccccc} \toprule \toprule \\ Indep. Var.: Market Gap X 1(Post)") 
				posthead("\cmidrule(lr){2-4}" "Dep. Var.:  & & & \\") 
				booktabs								
				nonumbers 
				mtitles("All events" "Major events" "\\$15 events") 
				collabels(none)  
				cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)) ) 
				starlevels(* 0.1 ** 0.05 *** 0.01) 						
				keep(D)   
				coeflabel(D "Log new hires") 
				noobs
		;
		esttab ln_new_hires_policya*
				using "$figures_tables/table5_sg_market_poach_did.tex",  
				append fragment
				nolines  
				booktabs								
				nonumbers 
				nomtitles
				collabels(none)  
				cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)) ) 
				starlevels(* 0.1 ** 0.05 *** 0.01) 						
				keep(D)   
				coeflabel(D "Log large retailer new hires") 
				noobs
		;
		esttab ln_new_hires_othera*
				using "$figures_tables/table5_sg_market_poach_did.tex",  
				append fragment
				nolines  
				booktabs								
				nonumbers 
				nomtitles
				collabels(none)  
				cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)) ) 
				starlevels(* 0.1 ** 0.05 *** 0.01) 						
				keep(D)   
				coeflabel(D "Log other new hires") 
				stats(
					N Ncz Tstd preMean_ln_new_hires preMean_ln_new_hires_policy preMean_ln_new_hires_other CZFE etimeFE, 
					fmt(%12.0gc) 
					label("Obs" "CZs" "St. dev. market gap" "Log new hires - all" "Log large retailer new hires" "Log other new hires" "CZ FEs" "Month from event FEs")
				)
				prefoot(\midrule) 
				postfoot(\bottomrule \bottomrule \end{tabular} \end{threeparttable} )
				substitute("Log new hires - all" "\midrule \textit{Pre-treatment mean} \\ Log new hires" "CZ FEs" "\midrule CZ FEs")
		;
		#d cr

		
		